package com.hky.front_end_monitor.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hky.front_end_monitor.constant.Constants;
import com.hky.front_end_monitor.entity.SysFirstPaint;
import com.hky.front_end_monitor.entity.SysLargestContentfulPaint;
import com.hky.front_end_monitor.service.SysLargestContentfulPaintService;
import com.hky.front_end_monitor.mapper.SysLargestContentfulPaintMapper;
import com.hky.front_end_monitor.utils.NumberUtils;
import org.springframework.stereotype.Service;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @author hello
 * @description 针对表【sys_largest_contentful_paint】的数据库操作Service实现
 * @createDate 2022-07-28 22:40:40
 */
@Service
public class SysLargestContentfulPaintServiceImpl extends ServiceImpl<SysLargestContentfulPaintMapper, SysLargestContentfulPaint>
        implements SysLargestContentfulPaintService {

    @Override
    public boolean storeLcp(String uuid, Map map) {
        SysLargestContentfulPaint lcp = new SysLargestContentfulPaint();
        lcp.setLargestContentfulPaintId(uuid);
        Map data = ((Map) (map.get(Constants.metricsName.LCP.value)));
        lcp.setStartTime(NumberUtils.toDouble(data.get("startTime")));
        LinkedHashMap entryInfo = (LinkedHashMap) (data).get("entry");
        lcp.setEntryName((String) entryInfo.get("name"));
        lcp.setEntryType((String) entryInfo.get("entryType"));
        lcp.setEntryStartTime(NumberUtils.toDouble(entryInfo.get("startTime")));
        lcp.setEntryDuration(NumberUtils.toDouble(entryInfo.get("duration")));
        lcp.setEntrySize(NumberUtils.toDouble(entryInfo.get("size")));
        lcp.setEntryRenderTime(NumberUtils.toDouble(entryInfo.get("renderTime")));
        lcp.setEntryLoadTime(NumberUtils.toDouble(entryInfo.get("loadTime")));
        lcp.setEntryId((String) entryInfo.get("id"));
        lcp.setEntryUrl((String) entryInfo.get("url"));
        lcp.setEntryFirstAnimateFrameTime(NumberUtils.toDouble(entryInfo.get("firstAnimatedFrameTime")));
        return this.save(lcp);
    }
}




